package com.ghn.cocknovel.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.coorchice.library.SuperTextView;
import com.ghn.cocknovel.R;

/**
 * admin
 * 2018/11/13
 * content :
 */
public abstract class BaseDialog extends Dialog implements View.OnClickListener {
    private LinearLayout mDialogBaseContent;
    private SuperTextView mDialogBaseNotBtn;
    private SuperTextView mDialogBaseYesBtn;
    public Context mContext;

    public BaseDialog(@NonNull Context context) {
        super(context, R.style.dialogstyle);
        mContext = context;
        initView();
        initData();
    }

    protected abstract void initData();

    private void initView() {
        setContentView(R.layout.dialog_base);
        mDialogBaseContent = findViewById(R.id.dialog_base_content);
        mDialogBaseNotBtn = findViewById(R.id.dialog_base_not_btn);
        mDialogBaseYesBtn = findViewById(R.id.dialog_base_yes_btn);
        mDialogBaseNotBtn.setOnClickListener(this);
        mDialogBaseYesBtn.setOnClickListener(this);
        //获取子类View 填充到  父View
        View.inflate(mContext, getChildView(), mDialogBaseContent);
    }

    public abstract int getChildView();

    protected BaseDialog setYesText(String text) {
        mDialogBaseYesBtn.setText(text);
        return this;
    }

    protected BaseDialog setYesVisibility(int visibility) {
        mDialogBaseYesBtn.setVisibility(visibility);
        return this;
    }

    protected BaseDialog setNotText(String text) {
        mDialogBaseNotBtn.setText(text);
        return this;
    }

    protected BaseDialog setNotVisibility(int visibility) {
        mDialogBaseNotBtn.setVisibility(visibility);
        mDialogBaseYesBtn.setLeftBottomCornerEnable(true);
        return this;
    }

    public BaseDialog setBaseCancelable(boolean flag) {
        super.setCancelable(flag);
        return this;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.dialog_base_not_btn) {
            dismiss();
            if (baseDialogClickListener != null) {
                baseDialogClickListener.notClick(v);
            }

        } else if (i == R.id.dialog_base_yes_btn) {
            if (baseDialogClickListener != null) {
                baseDialogClickListener.YesClick(v);
            }

        }
    }

    public Dialog setDialogCancelable(boolean flag) {
        super.setCancelable(flag);
        return this;
    }

    baseDialogClickListener baseDialogClickListener;

    protected void setBaseDialogClickListener(BaseDialog.baseDialogClickListener baseDialogClickListener) {
        this.baseDialogClickListener = baseDialogClickListener;
    }

    public interface baseDialogClickListener {
        void YesClick(View view);

        void notClick(View view);
    }
}
